#include "../common/message.h"
#include "../common/net.h"
#include "../common/dispather.h"
#include "../server/rpc_route.h"
void Add(const Json::Value &req, Json::Value &rsp)
{
    int num1 = req["num1"].asInt();
    int num2 = req["num2"].asInt();
    rsp = num1 + num2;
}

int main()
{
    auto router = std::make_shared<rpc::server::RpcRouter>();
    std::unique_ptr<rpc::server::SDercribeFactory> desc_factory(new rpc::server::SDercribeFactory());
    desc_factory->setMethodName("Add");
    desc_factory->setParam("num1", rpc::server::VType::INTEGRAL);
    desc_factory->setParam("num2", rpc::server::VType::INTEGRAL);
    desc_factory->setReturnType(rpc::server::VType::INTEGRAL);
    desc_factory->setCallback(Add);
    router->registerMethod(desc_factory->build());

    auto cb = std::bind(&rpc::server::RpcRouter::onRpcRequest, router.get(), std::placeholders::_1, std::placeholders::_2);

    auto dispather = std::make_shared<rpc::dispather>();
    dispather->registerHandler<rpc::RpcRequest>(lxprpc::MType::REQ_RPC, cb);

    auto server = rpc::ServerFactory::create(9090);
    auto message_cb = std::bind(&rpc::dispather::onMessage, dispather.get(), std::placeholders::_1, std::placeholders::_2);
    server->setMessageCallback(message_cb);
    server->start();
    return 0;
}
